package demo.pattern.proxy;

import demo.pattern.proxy.cglib.AlipyMethodInterceptor;
import demo.pattern.proxy.cglib.CglibUtil;
import demo.pattern.proxy.impl.AlipayToC;
import demo.pattern.proxy.impl.CommonPayment;
import demo.pattern.proxy.impl.ToBPaymentImpl;
import demo.pattern.proxy.impl.ToCPaymentImpl;
import demo.pattern.proxy.jdkProxy.AlipayInvocationHandler;
import demo.pattern.proxy.jdkProxy.JdkDynamicProxyUtil;
import net.sf.cglib.proxy.MethodInterceptor;

import java.lang.reflect.InvocationHandler;

/**
 * @ClassName ProxyDemo
 * @Description
 * @Author 47980
 * @Date 2020/8/9 15:26
 * @Version V_1.0
 **/
public class ProxyDemo {
    public static void main(String[] args) {
//        ToCPayment tocProxy = new AlipayToC(new ToCPaymentImpl());
//        tocProxy.pay();
//        ToCPayment toCPayment = new ToCPaymentImpl();
//        InvocationHandler handler = new AlipayInvocationHandler(toCPayment);
//        ToCPayment toCProxy = JdkDynamicProxyUtil.newProxyInstance(toCPayment, handler);
//        toCProxy.pay();
//
//        ToBPayment toBPayment = new ToBPaymentImpl();
//        InvocationHandler bhandler = new AlipayInvocationHandler(toBPayment);
//        ToBPayment toBProxy = JdkDynamicProxyUtil.newProxyInstance(toBPayment, bhandler);
//        toBProxy.pay();

//        CommonPayment commonPayment = new CommonPayment();
//        AlipayInvocationHandler alipayInvocationHandler = new AlipayInvocationHandler(commonPayment);
//        CommonPayment commonPaymentProxy = JdkDynamicProxyUtil.newProxyInstance(commonPayment, alipayInvocationHandler);
//        commonPaymentProxy.pay();

        CommonPayment commonPayment = new CommonPayment();
        MethodInterceptor MethodInterceptor = new AlipyMethodInterceptor();
        CommonPayment proxy = CglibUtil.createProxy(commonPayment, MethodInterceptor);
        proxy.pay();

        ToCPayment toCPayment = new ToCPaymentImpl();
        ToCPayment tocProxy = CglibUtil.createProxy(toCPayment, MethodInterceptor);
        tocProxy.pay();
    }
}
